package com.zyx.springretry.controller;

import com.zyx.springretry.common.exception.BusinessException;
import com.zyx.springretry.common.resp.CommonResponse;
import com.zyx.springretry.service.RetryService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * spring retry 案例
 * <p>
 * reference: <a href="https://blog.csdn.net/cckevincyh/article/details/112347200">Spring Boot中使用Spring-Retry重试框架</a>
 *
 * @author Yaxi.Zhang
 * @since 2023/2/27 11:06
 */
@RestController
@RequestMapping("/retry")
public class RetryController {

    @Resource
    private RetryService retryService;

    @GetMapping("/ping")
    public CommonResponse<String> ping() {
        return CommonResponse.success("pong", "调用成功");
    }

    @GetMapping("/service1")
    public CommonResponse<String> service1() {
        try {
            retryService.service1();
        } catch (IllegalAccessException e) {
            throw new BusinessException("wrong");
        }
        return CommonResponse.success("service1", "service1调用成功");
    }



}
